/**
 * Created by Weizehua on 2017/1/20.
 */

export function tr(s: string|TemplateStringsArray, ...v: any[]): string {
    if (s instanceof Array) {
        return Translator.translateRaw(<TemplateStringsArray>s, ...v);
    }
    return Translator.translate(<string>s);
}

enum Locale {
    EN,
    CN
}

class Translator {
    static translate(s: string) {
        if (this._locale != this._defaultLocale) {
            throw new Error(`no translate for locale : ${this._locale}`);
        }
        return s;
    }

    static translateRaw(s: TemplateStringsArray, ...v: string[]) {
        if (this._locale != this._defaultLocale) {
            throw new Error(`no translate for locale : ${this._locale}`);
        }
        return String.raw(s, ...v);
    }

    //noinspection JSUnusedGlobalSymbols
    static get locale(): Locale {
        return Translator._locale;
    }

    private static _locale = Locale.EN;
    private static _defaultLocale = Locale.EN;
}
